package cn.edu.scau.cmi.huangzhiyuan.client;

import cn.edu.scau.cmi.huangzhiyuan.singleton.President;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class SingletonClient extends Application {
	public static President president = null;
	public static Label display = new Label("尚未创建主席");

	@Override
	public void start(Stage primaryStage) {
		// 创建主席按钮
		Button addBt = new Button("创建主席");
		// 创建查看hashcode按钮
		Button checkBt = new Button("查看hashcode");
		
		Image image = new Image("file:src/main/resources/img/avatar.jpg");
		ImageView imageView = new ImageView(image);
		
		// 放置组件
		GridPane pane = new GridPane();
		pane.add(addBt, 0, 0);
		pane.add(checkBt, 1, 0);
		pane.add(display, 0, 1, 2, 1);

		
		// 添加监听器
		addBt.setOnAction(event -> {
			// 添加主席
			president = President.getInstance();
			// 展示主席
			display.setText(president.getName());
		});
		checkBt.setOnAction(event -> {
			if (president != null) {
				display.setText(String.valueOf(president.hashCode()));
			} else {
				display.setText("你还未创建主席");
			}
		});
		
		
		// 设置面板
		Scene scene = new Scene(pane, 400, 400);

		// 放置面板
		primaryStage.setScene(scene);
		
		// 展示
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}
}
